package com.yang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yang.domain.OrderGoodsDetails;
import com.yang.service.OrderGoodsDetailsService;
import com.yang.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 订单货源明细Controller
 *
 * @author 不是菜鸡爱编程
 * @date 2024-02-18
 */
@RestController
@RequestMapping("/orderGoodsDetails")
@Api(tags = "订单货源明细模块", value = "订单货源明细Controller")
public class OrderGoodsDetailsController {
    @Autowired
    private OrderGoodsDetailsService orderGoodsDetailsService;

    /**
     * 查询订单货源明细列表
     */
    @ApiOperation("查询订单货源明细列表")
    @GetMapping("/list")
    public IPage<OrderGoodsDetails> list(OrderGoodsDetails orderGoodsDetails) {
        //startPage();
        //List<OrderGoodsDetails> list = orderGoodsDetailsService.selectOrderGoodsDetailsList(orderGoodsDetails);
        //return getDataTable(list);
        return null;
    }


    /**
     * 获取订单货源明细详细信息
     */
    @ApiOperation("获取订单货源明细详细信息")
    @GetMapping(value = "/{orderId}")
    public R getInfo(@PathVariable("orderId") String orderId) {
        return R.ok().setData(orderGoodsDetailsService.list(new LambdaQueryWrapper<OrderGoodsDetails>()
                .eq(OrderGoodsDetails::getOrderId, orderId)));
    }

    /**
     * 新增订单货源明细
     */
    @ApiOperation("新增订单货源明细")
    @PostMapping
    public R add(@RequestBody OrderGoodsDetails orderGoodsDetails) {
        return R.ok().setData(orderGoodsDetailsService.save(orderGoodsDetails));
    }

    /**
     * 修改订单货源明细
     */
    @ApiOperation("修改订单货源明细")
    @PutMapping
    public R edit(@RequestBody OrderGoodsDetails orderGoodsDetails) {
        return R.ok().setData(orderGoodsDetailsService.update(orderGoodsDetails, new LambdaQueryWrapper<OrderGoodsDetails>()
                .eq(OrderGoodsDetails::getGoodsId, orderGoodsDetails.getGoodsId())
                .eq(OrderGoodsDetails::getOrderId, orderGoodsDetails.getOrderId())));
    }

    /**
     * 删除订单货源明细
     */
    @ApiOperation("删除订单货源明细")
    @DeleteMapping("/{orderIds}")
    public R remove(@PathVariable String[] orderIds) {
        return R.ok().setData(orderGoodsDetailsService.removeByIds(Arrays.asList(orderIds)));
    }
}
